package com.huang.datebase;

import java.sql.*;

/**
 * 数据库连接和关闭
 */
public class DbUtil {

	private static final String URL = "jdbc:mysql://localhost:3306/userinfo";
	private static final String USER = "root";
	private static final String PASSWORD = "88888888";


	public static Connection getConnection(){

		try {
			Class.forName("com.mysql.cj.jdbc.Driver");
			Connection connection = DriverManager.getConnection(URL,USER,PASSWORD);
			return connection;

		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException throwables) {
			throwables.printStackTrace();
		}
		return null;

	}

	public static void close(Connection connection,Statement statement, PreparedStatement ps, ResultSet resultSet){

			try {
				if (connection != null) {
					connection.close();
				}
				if (ps != null) {
					ps.close();
				}
				if (resultSet != null) {
					resultSet.close();
				}
			} catch (SQLException throwables) {
				throwables.printStackTrace();
			}

	}
}
